package kiwi.assist.dev.guieditor.view {
	import org.aswing.JScrollPane;

	import kiwi.assist.dev.guieditor.model.UiConfig;
	import kiwi.util.DisplayObjectUtils;

	import org.aswing.JAccordion;
	import org.aswing.JList;
	import org.aswing.event.ListItemEvent;

	/**
	 * ui列表
	 * 没什么特别的只是为了包装而已
	 * @author zhangming.luo
	 */
	public class UiList extends JAccordion {
		private var _types : *;
		private var _allList : * = {};
		private var _allListData : * = {};
		private var defaultList : JList;

		public function UiList() {
			defaultList = newList();
			setTypeData({button:"按钮类", label:"标签类", tab:"tab分页", progress:"进度条类", list:"列表类", icon:"图标类"});
		}

		private function newList() : JList {
			var list : JList = new DoubleClickList();
			list.addEventListener(ListItemEvent.ITEM_DOUBLE_CLICK, dispatchEvent);
			list.addEventListener(ListItemEvent.ITEM_CLICK, dispatchEvent);
			return list;
		}

		private function setTypeData(types : *) : void {
			_types = types;
			removeAll();
			_allList = {"default":defaultList};
			_allListData = {"default":[]};
			var pane : JScrollPane = new JScrollPane();
			pane.append(defaultList);
			appendTab(pane, "默认");
			for (var type:String in _types) {
				_allList[type] = newList();
				_allListData[type] = [];
				pane = new JScrollPane();
				pane.append(_allList[type]);
				appendTab(pane, _types[type] || type);
			}
		}

		public function setListData(list : Array, tabProperty : String) : void {
			resetAll();
			for each (var item:UiConfig in list) {
				_allListData[item[tabProperty] || "default"].push(item);
			}
			defaultList.setListData(_allListData["default"]);
			for (var type:String in _types) {
				JList(_allList[type]).setListData(_allListData[type]);
				DisplayObjectUtils.doubleClickEnabled(_allList[type]);
			}
		}

		private function resetAll() : void {
			_allListData["default"] = [];
			for (var type:String in _types) {
				_allListData[type] = [];
			}
		}
	}
}
import org.aswing.Component;
import org.aswing.JList;

class DoubleClickList extends JList {
	override protected function addHandlersToCell(cellCom : Component) : void {
		super.addHandlersToCell(cellCom);
		cellCom.doubleClickEnabled = true;
	}
}